package com.foreknow.demo5;

import com.sun.org.apache.xpath.internal.operations.Or;
import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;

import java.nio.file.LinkPermission;
import java.util.Scanner;

public class Test {
    public void printBooksInfo(Book[] books) {
        for (int i = 0;i<books.length;i++){
            Book book = books[i];
            System.out.println(book.getId()+"---"+book.getName()+"---"+book.getPrice()+"---"+book.getStorage());
        }
    }
    public Order bubBooks(Book[] books){
        Scanner input = new Scanner(System.in);
        //1. 先创建Order类的对象
        Order order = new Order("0001");
        for(int i = 0;i<3;i++){
            System.out.println("请输入图书的编号: ");
            int pid = input.nextInt();
            System.out.println("请输入购买数量: ");
            int num = input.nextInt();
            //2. 要将用户购买的商品保存到Order中的 OrderItem[]数组中?
            Orderltem item = new Orderltem(books[pid-1].getName(),books[pid-1].getPrice(),num);
            //要把item对象保存到Order对象中的OrderItem【】数组中(向数组中添加元素要通过下标)
            order.setItems(item,i);
            System.out.println("请继续购买图书");
        }
        return  order;
    }
    public static void main(String[] args) {
        Test test = new Test();
        Book[] books = new Book[3];
        Book book1 = new Book(1,"java",33.45,50);
        Book book2 = new Book(2,"jsp",55.45,150);
        Book book3 = new Book(3,"SpringBoot",77.45,250);
        books[0]= book1;
        books[1]= book2;
        books[2]= book3;
        //调用输出Book类
        test.printBooksInfo(books);
        Order order = test.bubBooks((books));
        System.out.println("订单的编号："+order.getOrderId());
        System.out.println("订单的总额："+order.getTotal());
    }
}